package com.atguigu.tingshu.search.receiver;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import io.micrometer.common.util.StringUtils;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SearchReceiver {
    @Autowired
    private SearchService searchService;

    /**
     * 上架监听器
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void albumImport(ConsumerRecord<String,String> record){
        String value = record.value();
        if (StringUtils.isNotEmpty(value)){
            Long id = Long.valueOf(value);
            searchService.upperAlbum(id);
        }
    }

    /**
     * 下架监听器
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void albumLower(ConsumerRecord<String,String> record){
        String value = record.value();
        if (StringUtils.isNotEmpty(value)){
            Long id = Long.valueOf(value);
            searchService.lowerAlbum(id);
        }
    }
}
